package top.jianx.music.base;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import top.jianx.music.api.RequestCallback;

import java.io.IOException;

/**
 * 请求回调接口 默认实现
 * @param <TResult> 返回数据泛型
 *
 * @author Jianx <jianx70687547@gmail.com>
 * @date 2022/1/16 11:46
 */
public abstract class SimpleRequestCallback<TResult> implements RequestCallback<TResult> {
    private final static Logger logger = LoggerFactory.getLogger(SimpleRequestCallback.class);

    /**
     * onFailure简化为默认打印错误
     *
     * @param e
     */
    @Override
    public void onFailure(IOException e) {
        logger.warn(">>>>>>>>>>>>>> [SimpleRequestCallback]请求失败:{}", e.getMessage());
        e.printStackTrace();
    }

    @Override
    public void onSuccess(TResult tResult) {
        logger.warn(">>>>>>>>>>>>>> [SimpleRequestCallback]请求成功:{}", JSONUtil.toJsonPrettyStr(tResult));
    }
}
